package com.ecomm.util;

/**
 * <p>Title: OA2.0产品研发</p>
 * <p>Description: 力求规范严谨</p>
 * <p>Copyright: Copyright (c) 2002</p>
 * <p>Company: 联合易讯</p>
 * @author 侯万春
 *
 * @version 1.0
 */

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.log4j.PropertyConfigurator;

import java.io.File;
import java.util.Iterator;
import java.util.Properties;

/**
 * This class serves as the entry of the log system.
 */
public class Logger {
    
    static
    {
        try {
            System.out.println("开始日志系统........");
            Properties prop = new Properties();
            for (Iterator it = Config.getKeys("log4j"); it.hasNext();) {
                String key = (String) it.next();
                if ("log4j.rootCategory".equals(key)) {
                    String s = Config.getList(key).toString();
                    if (s.length() > 2) {
                        s = s.substring(1, s.length() - 1);
                    } else {
                        s = "DEBUG, config1";
                    }
                    prop.setProperty(key, s);
                } else {
                    prop.setProperty(key, Config.getString(key));
                }
            }
            
            String filePath = (String) prop.get("log4j.appender.config2.File");
            if (filePath != null) {
                System.out.println("filePath----------"+filePath);
            }
            if (!prop.isEmpty()) {
                PropertyConfigurator.configure(prop);
            }
        } catch (Exception e) {
            System.out.println("不能初始化日志系统。错误信息：" + e.getMessage());
            e.printStackTrace();
        }
        //BasicConfigurator.configure();
    }
    
    
    public static Log getLog(Class clazz) {
        return LogFactory.getLog(clazz);
    }
    
    public static Log getLog(String name) {
        return LogFactory.getLog(name);
    }
    
}
